package Presenter;
import Model.Tile;

/**
 * @author Josh Weinflash
 * @description Map is an array of tiles
 *
 */
public class Map 
{
	Tile[] tileArray;

	/** 
	 * Constructor for Map (just a holder of the tiles)
	 */
	public Map()
	{
		tileArray = new Tile[45];
	}
		
	/**
	 * sets the tiles to the default specification
	 */
	public void setDefaultMap()
	{
		// row 1
		tileArray[0] = new Tile("P"); tileArray[1] = new Tile("P"); tileArray[2] = new Tile("M1");
		tileArray[3] = new Tile("P"); tileArray[4] = new Tile("R"); tileArray[5] = new Tile("P");
		tileArray[6] = new Tile("M3"); tileArray[7] = new Tile("P"); tileArray[8] = new Tile("P");
		
		// row 2
		tileArray[9] = new Tile("P"); tileArray[10] = new Tile("M1"); tileArray[11] = new Tile("P");
		tileArray[12] = new Tile("P"); tileArray[13] = new Tile("R"); tileArray[14] = new Tile("P");
		tileArray[15] = new Tile("P"); tileArray[16] = new Tile("P"); tileArray[17] = new Tile("M3");
		
		// row 3 ** THE MAP DOES NOT HAVE A TILE FOR TOWN **
		tileArray[18] = new Tile("M3"); tileArray[19] = new Tile("P"); tileArray[20] = new Tile("P");
		tileArray[21] = new Tile("P"); tileArray[22] = new Tile("T"); tileArray[23] = new Tile("P"); 
		tileArray[24] = new Tile("P"); tileArray[25] = new Tile("P"); tileArray[26] = new Tile("M1");
		
		// row 4
		tileArray[27] = new Tile("P"); tileArray[28] = new Tile("M2"); tileArray[29] = new Tile("P");
		tileArray[30] = new Tile("P"); tileArray[31] = new Tile("R"); tileArray[32] = new Tile("P");
		tileArray[33] = new Tile("M2"); tileArray[34] = new Tile("P"); tileArray[35] = new Tile("P");
		
		// row 5
		tileArray[36] = new Tile("P"); tileArray[37] = new Tile("P"); tileArray[38] = new Tile("M2");
		tileArray[39] = new Tile("P"); tileArray[40] = new Tile("R"); tileArray[41] =  new Tile("P");
		tileArray[42] = new Tile("P"); tileArray[43] = new Tile("P"); tileArray[44] = new Tile("M2");
			
	}
	
	/**
	 * Produce resources for respective owners (condition checking in tile.produce() ) 
	 */
	public void produce() {
		for (int i=0; i<tileArray.length; i++) {
			
			tileArray[i].produce();
		}
	}

	
	// Following method written by Matt
	/**
	 * Returns the tile array
	 * @return
	 */
	public Tile[] getTileArray() {
		return tileArray;
	}
	
	/**
	 * Sets the tile array to the given one.
	 * @param tiles
	 */
	public void setTileArray(Tile[] tiles){
		tileArray = tiles;
	}
	
	/**
	 * Returns a specific tile based on coordinates
	 * @param y
	 * @param x
	 * @return Tile
	 */
	public Tile getTile(int y, int x) {
		int index = 9 * y + x;
		if(x < 0 || y < 0) {
			return null;
		} else if(index > tileArray.length-1){
			return null;
		}
		return tileArray[index];
	}
}

